package org.hhchat.leetcode.tree;

import org.hhchat.leetcode.dataStruct.TreeNode;

/**
 * Created this one by HMH on 2017/10/3.
 */
public class code669_easy {

    static class Solution {
        public TreeNode trimBST(TreeNode root, int L, int R) {
            visit(root, L, R);
            return root;
        }

        public void visit(TreeNode treeNode, int L, int R) {
            if (treeNode == null) {
                return ;
            }
            visit(treeNode.right, L, R);
            visit(treeNode.left, L, R);
            if (treeNode.val > R || treeNode.val < L) {
                treeNode = delete(treeNode);
            }
        }

        public TreeNode delete(TreeNode root) {
            if (root.right != null) {
                return root.right;
            }
            if (root.left != null) {
                return root.left;
            }
            return null;
        }

    }
    public static void main(String[] args){

    }

}
